/**
 * @author 徐楠
 * @date 2022/2/26 19:23
 * @version 1.0
 */

package com.xunan.likou;

import java.util.HashMap;
import java.util.Map;

public class MaximumNumberOfConsecutive1 {
    public static void main(String[] args) {
        int[] nums = {0, 1};
        int result = findMaxConsecutiveOnesPlus(nums);
        System.out.println(result);

    }


    public static int findMaxConsecutiveOnesPlus(int[] nums) {
        int maxCount = 0, count = 0;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            if (nums[i] == 1) {
                count++;
            } else {
                maxCount = Math.max(maxCount, count);
                count = 0;
            }
        }
        maxCount = Math.max(maxCount, count);
        return maxCount;
    }

    public static int findMaxConsecutiveOnes(int[] nums) {
        int length = nums.length;
        int Max = 0;
        int result = 0;
        if (length == 1) {
            if (nums[0] == 0) {
                return 0;
            } else if (nums[0] == 1) {
                return 1;
            }
        }

        for (int i = 0; i < length; i++) {
            if (nums[i] == 0) {
                if (result < Max) {
                    result = Max;
                }
                Max = 0;
                continue;
            }
            if (nums[i] == 1) {
                if (Max == 0) {
                    Max++;
                }
                if (i + 1 <= length - 1 && nums[i] == nums[i + 1]) {
                    Max++;
                }
            }

        }
        if (result < Max) {
            result = Max;
        }
        return result;

    }


}
